#include <iostream>
#include <memory>
#include "TcpServer.hpp"
#include "Protocol.hpp"
// #include "PollServer.hpp"
// #include "SelectServer.hpp"
// #include "ReactorServer.hpp"

#include "ReactorMorePro.hpp"
#include "Util.hpp"

using std::cout;
using std::endl;

Response HandlerResp(const Request& req)
{
    Response resp;
    switch(req._op)
    {
        case '+':   
            resp._res = req._x + req._y;
            break;
        case '-':
            resp._res = req._x - req._y;
            break;
        case '*':
            resp._res = req._x * req._y;
            break;
        case '/':
            if(req._y == 0)
            {
                resp._errno = 1;
                resp._errStr = "division zero";
                break;
            }
            resp._res = req._x / req._y;
            break;
        case '%':
            if(req._y == 0)
            {
                resp._errno = 1;
                resp._errStr = "division zero";
                break;
            }
            resp._res = req._x % req._y;
            break;
        default:
            resp._errno = 2;
            resp._errStr = "unvalid op";
    }
    return resp;
}

int main()
{
    Server::ptr sver = std::unique_ptr<ReactorMorePro>(new ReactorMorePro(HandlerResp));
    Util::Daemon();
    sver->Dispatcher();
    return 0;
}